//后台管理模块
export default {
  state: {
    menuState: false,//左侧菜单的收张状态
    menuIcon: 'el-icon-s-fold',
    selectTab: '-1',//菜单id
    tabList: [],
  },
  //同步方法
  mutations: {
    //收起/打开左侧菜单方法
    activeMenu(state) {
      if (state.menuState) {
        state.menuState = false;
        state.menuIcon = 'el-icon-s-fold';
      } else {
        state.menuState = true;
        state.menuIcon = 'el-icon-s-unfold';
      }
    }, addTab(state, value) {
      //es6语法，返回数组中的下标，没有-1
      let result = state.tabList.findIndex(item => item.id === value.id);
      if (result === -1) {
        state.tabList.push(value);
        state.selectTab = value.id + '';
      } else {
        //将tab标签设置为选中
        state.selectTab = state.tabList[result].id + '';
      }
    }, clickTab(state, index) {
      if (index - 1 !== -1) {
        state.selectTab = state.tabList[index - 1].id + '';
      } else {
        state.selectTab = '-1';
      }
    }, updateSelectTab(state, value) {
      state.selectTab = value;
    },
  },
  //异步方法
  actions: {},
}
